package com.qingcloud.df.executor.launcher;
//
//import com.qingcloud.df.executor.constant.RuntimeConfigKeyConstant;
//import com.qingcloud.df.executor.launcher.process.ComponentExecutorHandle;
//import com.qingcloud.df.executor.queue.ComponentMessage;
//import com.qingcloud.df.sdk.component.context.CompInstContext;
//import com.qingcloud.df.sdk.component.context.CompInstRuntimeHolder;
//import com.qingcloud.df.sdk.component.context.ConfigManager;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
//import tech.powerjob.worker.core.processor.ProcessResult;
//import tech.powerjob.worker.core.processor.TaskContext;
//import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
//
@Component
public class RemoteTaskLauncher extends TaskLauncher {//implements BasicProcessor {
//    Logger log =  LoggerFactory.getLogger(TaskLauncher.class);
//
//
//    @Value("${qingcloud.executor.task.type}")
//    private String taskType;
//    @Override
//    public ProcessResult process(TaskContext taskContext) throws Exception {
//        if(taskType.equals("local")) {
//            return new ProcessResult(true, "不需要远程执行！");
//        }
//        String jobParam = taskContext.getJobParams();
//        log.debug("组件实例id[" + jobParam + "]定时任务开始");
//        try {
//            int instanceId = -1;
//            String env = RuntimeConfigKeyConstant.DEV_ENV;
//            String[] arrays = jobParam.split("#");
//            if(arrays.length>1){
//                instanceId = Integer.parseInt(arrays[0]);
//                env = arrays[1];
//            }else{
//                instanceId = Integer.parseInt(jobParam);
//            }
//            if (instanceId<=0) {
//                log.error("组件实例id不能为空");
//                return new ProcessResult(false, "组件实例id不能为空");
//            }
//            //查询组件信息
//            CompInstContext context = ConfigManager.loadByInstanceId(instanceId, env);
//            if(context == null) {
//                log.error("组件实例id【" + instanceId + "】未找到相应配置信息");
//                return new ProcessResult(false, "组件实例id【" + instanceId + "】未找到相应配置信息");
//            }
//            runComponent(context);
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error("组件id[" + jobParam + "]定时任务执行失败");
//        }
//        return new ProcessResult(true, "执行成功");
//    }
//
//    private void runComponent(CompInstContext context) {
//        CompInstRuntimeHolder runtimeHolder = null;
//        try {
//            ComponentMessage message=  new ComponentMessage();
//            message.setTopic(context.getTopic());
//            message.setInstanceId(context.getId());
//            message.setEnv(context.getEnv());
//            ComponentExecutorHandle.fusion(message);
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if(runtimeHolder!=null) CompInstRuntimeHolder.removeContext();
//        }
//    }
}
